package com.marvels.financial.consum.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.dubbo.coreservice.service.ILoanApplyInfoService;
import com.marvels.dubbo.coreservice.service.TrialCostService;
import com.marvels.financial.consum.FinancialConsumerCoreApi;
import com.marvels.financial.loan.dto.MpCarInsuranceServiceFee;
import com.marvels.financial.loan.dto.TrialCostConditionDTO;
import com.marvels.financial.loan.dto.TrialCostDataDTO;
import com.marvels.financial.loan.dto.UserBankDTO;

import cn.hutool.core.bean.BeanUtil;

@Component
public class FinancialConsumerCoreImpl implements FinancialConsumerCoreApi {

	@Autowired
	private TrialCostService trialCostService;
	
	@Autowired
	private ILoanApplyInfoService loanApplyInfoService;
	
	@Override
	public TrialCostDataDTO countData(TrialCostConditionDTO dto) {
		try {
			com.dragon.loan.dto.TrialCostConditionDTO param = new com.dragon.loan.dto.TrialCostConditionDTO();
			BeanUtil.copyProperties(dto, param);
			com.dragon.loan.dto.TrialCostDataDTO apiResult = trialCostService.countData(param);
			TrialCostDataDTO result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), TrialCostDataDTO.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerCoreApi.countData direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerCoreApi.countData error", e);
			return null;
		}
	}

	@Override
	public List<TrialCostDataDTO> listQuery(TrialCostConditionDTO dto) {
		try {
			com.dragon.loan.dto.TrialCostConditionDTO param = new com.dragon.loan.dto.TrialCostConditionDTO();
			BeanUtil.copyProperties(dto, param);
			List<com.dragon.loan.dto.TrialCostDataDTO> apiResult = trialCostService.listQuery(param);
			List<TrialCostDataDTO> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), TrialCostDataDTO.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerCoreApi.listQuery direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerCoreApi.listQuery error", e);
			return null;
		}
	}

	@Override
	public List<TrialCostDataDTO> costCollect(TrialCostConditionDTO dto) {
		try {
			com.dragon.loan.dto.TrialCostConditionDTO param = new com.dragon.loan.dto.TrialCostConditionDTO();
			BeanUtil.copyProperties(dto, param);
			List<com.dragon.loan.dto.TrialCostDataDTO> apiResult = trialCostService.costCollect(param);
			List<TrialCostDataDTO> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), TrialCostDataDTO.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerCoreApi.costCollect direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerCoreApi.costCollect error", e);
			return null;
		}
	}

	@Override
	public MpCarInsuranceServiceFee selectByOrderNumber(MpCarInsuranceServiceFee serviceFee) {
		try {
			com.dragon.loan.entity.MpCarInsuranceServiceFee param = new com.dragon.loan.entity.MpCarInsuranceServiceFee();
			BeanUtil.copyProperties(serviceFee, param);
			com.dragon.loan.entity.MpCarInsuranceServiceFee apiResult = trialCostService.selectByOrderNumber(param);
			MpCarInsuranceServiceFee result = JSONObject.parseObject(JSONObject.toJSONString(apiResult), MpCarInsuranceServiceFee.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerCoreApi.selectByOrderNumber direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerCoreApi.selectByOrderNumber error", e);
			return null;
		}
	}

	@Override
	public List<UserBankDTO> selectUserBankInfo(Map<String, Object> map) {
		try {
			List<com.dragon.loan.entity.AcUserBank> apiResult= loanApplyInfoService.selectUserBankInfo(map);
			List<UserBankDTO> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), UserBankDTO.class);
			MarvelsLogUtil.getInstance().info("FinancialConsumerCoreApi.selectUserBankInfo direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("FinancialConsumerCoreApi.selectUserBankInfo error", e);
			return null;
		}
	}

}
